const app = getApp();
const $api = require('../../../../request/api').API;

Page({
  data: {
    deviceId: '',
    miniToken: '',
    channelId: ''
  },
  onLoad(options) {
    const deviceinfo = options.deviceinfo.split('_');
    const deviceId = deviceinfo[0];
    const channelId = deviceinfo[1];
    const multiFlag = deviceinfo[5];
    const channelAbility = multiFlag === 'true' ? deviceinfo[6].split(',') : deviceinfo[2].split(',');
    const channelStatus = deviceinfo[3];
    this.setData({ deviceId, channelId });
    this.featchImouMiniToken(deviceId, channelId);
  },

  handleEvent(e) {
    console.log(e.detail);
  },

  /**
   * 获取临时token
   */
  featchImouMiniToken(deviceId, channelId) {
    const params = { deviceId, channelId };
    $api.createWeChatMiniProgramToken(params).then(res => {
      this.setData({ miniToken: res.result.data.miniToken });
    });
  }
});
